package com.lanou.beautifulwardrobe.cart;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lanou.beautifulwardrobe.dbHelper.UsersDBHelper;
import com.lanou.beautifulwardrobe.R;

/**
 * Created by dllo on 15/11/9.
 */
public class CartFragment extends Fragment {
    private RecyclerView cartRecyclerView;
    private GridLayoutManager manager;
    private int resultCode;
    private static CartFragment fragment;
    private LinearLayout cartFail, cartSuccess;
    private UsersDBHelper helper=UsersDBHelper.getInstance();

    public static CartFragment getInstance() {
        if (fragment == null) {
            fragment = new CartFragment();
        }
        return fragment;
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.maintab_cart_item, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        cartRecyclerView = (RecyclerView) view.findViewById(R.id.cartRecyclerView);
        cartFail = (LinearLayout) view.findViewById(R.id.cartFail);
        cartSuccess = (LinearLayout) view.findViewById(R.id.cartSuccess);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initView();
        initData();
    }

    private void initView() {
        manager = new GridLayoutManager(getActivity(), 1);

        View view = View.inflate(getContext(), R.layout.activity_login, null);
        TextView spaceUser = (TextView) view.findViewById(R.id.spaceUser);
//        Log.i("lanou",spaceUser.getText()+"**");

//        for (UsersEntity usersEntity : helper.queryAll()) {
//            if(spaceUser.getText().toString().equals(usersEntity.getUser())){
//                cartFail.setVisibility(View.VISIBLE);
//                cartSuccess.setVisibility(View.GONE);
//            }
//        }


//        if (spaceUser.getText().equals("")) {
//            cartFail.setVisibility(View.GONE);
//            cartSuccess.setVisibility(View.VISIBLE);
//        } else {
//
//        }

    }

    private void initData() {
        cartRecyclerView.setLayoutManager(manager);

    }
}
